//
//  HYLChatCell.m
//  qq通信
//
//  Created by hyl on 16/6/2.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "HYLChatCell.h"
#import "HYLChat.h"

//define this constant if you want to use Masonry without the 'mas_' prefix
#define MAS_SHORTHAND

//define this constant if you want to enable auto-boxing for default syntax
#define MAS_SHORTHAND_GLOBALS

#import "Masonry.h"
@interface HYLChatCell ()
@property (weak, nonatomic) IBOutlet UILabel *timeLable;
@property (weak, nonatomic) IBOutlet UIButton *contentButton;
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UIButton *otherContentButton;
@property (weak, nonatomic) IBOutlet UIImageView *otherImageView;

@end

@implementation HYLChatCell
-(void) awakeFromNib{
    self.contentButton.titleLabel.numberOfLines=0;
    self.otherContentButton.titleLabel.numberOfLines=0;
    
    //self.contentButton.titleLabel.preferredMaxLayoutWidth=100;
}
#pragma mark -implementaton
+(instancetype) chatCell:(UITableView *)tableView{

    HYLChatCell *cell=[tableView dequeueReusableCellWithIdentifier:@"message"];
    //
    return cell;
}
#pragma mark - setter/getter
-(void) setChat:(HYLChat *)chat{
    _chat=chat;
    self.timeLable.text=chat.time;
    if (self.chat.type==1) {
        [self setShowCellWithBool:YES isMeShowTimeLable:YES];
    } else {
        [self setShowCellWithBool:NO isMeShowTimeLable:NO];
    }
    
}
-(void) setShowCellWithBool:(BOOL) isMeShowContentButton isMeShowTimeLable:(BOOL) isMeShowTimeLable{
    if (isMeShowContentButton) {
        self.contentButton.hidden=!isMeShowContentButton;
        self.iconView.hidden=!isMeShowContentButton;
        self.otherContentButton.hidden=isMeShowContentButton;
        self.otherImageView.hidden=isMeShowContentButton;
        [self.contentButton setTitle:self.chat.text forState:UIControlStateNormal];
        [self.iconView layoutIfNeeded];
        [self.contentButton layoutIfNeeded];
        [self.contentButton updateConstraints:^(MASConstraintMaker *make) {
            //make.height.equalTo(CGRectGetMaxY(self.contentButton.titleLabel.frame));
            
            make.height.equalTo(self.contentButton.titleLabel.frame.size.height+30);
        }];
        [self.contentButton.titleLabel updateConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.contentButton).insets(UIEdgeInsetsMake(15, 15, 15, 15));
        }];
        [self layoutIfNeeded];
        self.chat.cellHight=MAX(CGRectGetMaxY(self.contentButton.frame), CGRectGetMaxY(self.iconView.frame))+10;
    } else {
        self.contentButton.hidden=YES;
        self.iconView.hidden=YES;
        self.otherContentButton.hidden=NO;
        self.otherImageView.hidden=NO;
        [self.otherContentButton setTitle:self.chat.text forState:UIControlStateNormal];
        [self.otherImageView layoutIfNeeded];
        [self.otherContentButton layoutIfNeeded];
        [self.otherContentButton updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(self.otherContentButton.titleLabel.frame.size.height+30);
        }];
        [self.otherContentButton.titleLabel updateConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.otherContentButton).insets(UIEdgeInsetsMake(15, 15, 15, 15));
        }];
        [self layoutIfNeeded];
        self.chat.cellHight=MAX(CGRectGetMaxY(self.otherContentButton.frame), CGRectGetMaxY(self.otherImageView.frame))+10;
    }

}
@end
